/*
 * ImagenesPlusDemonio.java
 *
 * Created on 21 de noviembre de 2006, 12:21 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.src.computec.radarplus.gestionimagenes.demonio;
import com.src.computec.radarplus.gestionimagenes.base.helper.BaseHelper;
import com.src.computec.radarplus.gestionimagenes.dao.BaseImagenesPlusDAO;
import com.src.computec.radar.base.dao.exception.DAOException;
import static com.src.computec.radarplus.gestionimagenes.base.constantes.ConstantesGenerales.SLEEP_LONG_TIME;
import java.util.List;

/**
 *
 * @author jlperea
 */
public class ImagenesPlusDemonio extends BaseHelper implements Runnable
{
    boolean aDormir = false;
    BaseImagenesPlusDAO dao = null;
    
    /** Creates a new instance of PoolArchivosDemonio */
    public ImagenesPlusDemonio() 
    {
        System.out.println("ImagenesPlusDemonio: ImagenesPlusDemonio: ");    
        dao = (BaseImagenesPlusDAO) this.getFactoryDAO().getImagenesPlusDAO();
    }
    
    public void run() 
    {
        while(true)
        {            
            try
            {                
                List bloqueImagenes = dao.getImagesToCopy(); 
                
                if(!bloqueImagenes.isEmpty())
                { 
                    aDormir = false;
                    dao.procesarBloqueImagenes(bloqueImagenes, "Thread 1");                    
                }
                else
                {
                    aDormir = true;
                }                
            
                if(aDormir)
                {
                    System.out.println("ImagenesPlusDemonio: run: SLEEP_LONG_TIME");
                    aDormir = false;
                    Thread.sleep(SLEEP_LONG_TIME);                    
                }
            } 
            catch(DAOException e)
            {
                System.out.println("ImagenesPlusDemonio: run: DAOException: " + e.toString()); 
                e.printStackTrace();
            }
            catch (InterruptedException e) 
            {
                System.out.println("ImagenesPlusDemonio: run: InterruptedException: " + e.toString()); 
                e.printStackTrace();
            }
            catch (Exception e) 
            {
                System.out.println("ImagenesPlusDemonio: run: Exception: " + e.toString()); 
                e.printStackTrace();
            }
        } 
    }   
    
}
